home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 11.0 KB | 312 lines | [TEXT/CWIE] |
- /* This file is part of the Internet Configuration system and is placed in the public domain for the benefit of all.
-
- This file holds all those miscellaneous little functions that are basically wrappers
- around existing OS functionality.
- */
-
- #import <Types.h>
- #import <Menus.h>
- #import "InternetConfig.h"
-
- /* ***** Event Manager Stuff ***** */
-
- /* A collection of useful ASCII character definitions. */
-
- enum {
- kNulChar = 0x000,
- kHomeChar = 0x001,
- kEnterChar = 0x003,
- kEndChar = 0x004,
- kHelpChar = 0x005,
- kBackSpaceChar = 0x008,
- kTabChar = 0x009,
- kLineFeedChar = 0x00A,
- kPageUpChar = 0x00B,
- kPageDownChar = 0x00C,
- kCRChar = 0x00D,
- kEscChar = 0x01B,
- kClearChar = 0x01B,
- kLeftArrowChar = 0x01C,
- kRightArrowChar = 0x01D,
- kUpArrowChar = 0x01E,
- kDownArrowChar = 0x01F,
- kSpaceChar = 0x020,
- kDelChar = 0x07F,
- kBulletChar = 0x0A5
- };
-
- /* A collection of useful virtual key code definitions. */
-
- enum {
- kUndoKeyCode = 122,
- kCutKeyCode = 120,
- kCopyKeyCode = 99,
- kPasteKeyCode = 118,
- kClearKeyCode = 71,
-
- kEscKeyCode = 53,
- kReturnKeyCode = 36,
- kEnterKeyCode = 52,
- kTabKeyCode = 48,
- kSpaceKeyCode = 49,
- KDeleteKeyCode = 51,
-
- kCommandKeyCode = 55,
- kShiftKeyCode = 56,
- kCapsLockKeyCode = 57,
- kOptionKeyCode = 58
- };
-
- /* ***** Memory Stuff ***** */
-
- enum {
- kHandleLockBit = 7,
- kHandlePurgeBit = 6,
- kHandleResourceBit = 5,
-
- kHandleLockMask = 0x080,
- kHandlePurgeMask = 0x040,
- kHandleResourceMask = 0x020
- };
-
- #if 0
-
- // These types are probably unnecessary for C.
-
- type
- /* A data structure for addresses memory as bytes. */
- BigBuffer = packed array [0..$0FFFFFF] of UInt8;
- BigBufferPtr = ^BigBuffer;
- BigBufferHandle = ^BigBufferPtr;
-
- /* Another for addressing memory as chars. */
- BigCharArray = packed array [0..$FFFFFF] of char;
- BigCharArrayPtr = ^BigCharArray;
- BigCharArrayHandle = ^BigCharArrayPtr;
-
- #endif
-
- extern pascal Boolean BlockCompare (void *lhsBaseAddr, void *rhsBaseAddr, SInt32 size);
- /* Compares two blocks of memory for equality.*/
-
- extern pascal void BlockFill (void *baseAddr, SInt32 size, SInt16 value);
- /* Fills a block of memory with the value. The memory is filled
- as bytes, ie the high byte of value is ignored.
- */
-
- /* ***** Resource Manager Stuff ***** */
-
- extern pascal ICError CheckMemError(Handle memoryHandle);
- extern pascal ICError CheckResError(Handle resourceHandle);
-
- extern pascal ICError AddNamedResource(Handle data, ResType theType, ConstStr255Param name);
- /* Adds data to the current resource file as a resource
- of type theType with the given name. It calculates a
- unique resource ID for the newly added resource. Note that,
- like AddResource, data comes back as either a resource
- handle (on noErr) or still a memory handle (on error).
- */
-
- extern pascal OSStatus Set1Resource(Handle theData, ResType theType, SInt16 theID);
- /* This routine sets the resource denoted by theType and theID to contain
- theData. If the resource does not currently exist, it is created.
- If it does currently exist, it is modified. theData is not disposed
- of.
- */
- extern pascal OSStatus Set1ResourcePtr(void *theData, SInt32 theDataSize, ResType theType, SInt16 theID);
- /* Works like Set1Resource except that you pass in a pointer and size. */
-
- extern pascal OSStatus Set1NamedResource(Handle theData, ResType theType, ConstStr255Param name);
- /* This routine sets the resource denoted by theType and name to contain
- theData. If the resource does not currently exist, it is created with
- a unique ID greater than 127. If it does currently exist, it is modified.
- theData is not disposed of.
- */
-
- /* ***** File Manager Stuff ***** */
-
- extern pascal OSStatus GetVolInfo (Str63 ioName, SInt16 *ioVRefNum, SInt16 ioVolIndex,
- SInt32 ioVCrDate);
- /* Returns information about the specified volume. Basically this is a wrapper
- around PBGetVInfo. See Files IM for a description of the meaning of the
- ioName, ioVRefNum and ioVolIndex parameters. This routine also returns
- the volume's creation date in ioVCrDate to aid in Poor Man's Alias Manager
- volume matching.
- */
-
- extern pascal OSStatus FindApplicationInDTDB (OSType creator, FSSpec *foundApplicationSpec);
- /* This routine attempts to find an application in the desktop database
- given its creator type.
- */
-
- extern pascal OSStatus FSpGetCatInfo (FSSpec *fss, SInt16 ioFDirIndex, CInfoPBRec *cpb);
- /* This routine is a simple wrapper around PBGetCatInfo. See Files IM
- for a description of the meaning of ioFDirIndex.
- Note that, despite the name, this routine can be called under System 6.
- */
-
- extern pascal OSStatus FSpSetCatInfo (FSSpec *fss, CInfoPBRec *cpb);
- /* This routine is a simple wrapper around PBSetCatInfo.
- Note that, despite the name, this routine can be called under System 6.
- */
-
- extern pascal OSStatus FSpCatMoveQ(FSSpec *fss, SInt32 destDirID);
- /* A nicer wrapper around PBCatMove. FSpCatMove is a horrible
- routine because it requires a dest FSSpec, rather than
- a dest dirID. CatMove is not good either because the
- Pascal interfaces define it to take a Str255 var rather
- than a StringPtr, so you can't pass nil for ioNewName.
- So instead, we write our own.
- */
-
- extern pascal OSStatus FileLocked (const FSSpec *fss);
- /* This routine returns true if the specified file is locked. Note that
- this provides no guarantee that you can write to the file, it merely
- checks all the things it can to see if any of them disable writing.
- */
-
- extern pascal OSStatus CopyFork (SInt16 sourceForkRefnum, SInt16 destForkRefnum, SInt32 bytesToCopy);
- /* This routine copies a file fork from sourceForkRefnum to destForkRefnum.
- The files must be positioned at where you want to start copying (usually
- at the beginning) and the routine copys bytesToCopy bytes from the source
- to the destination.
- */
-
- extern pascal OSStatus CopyForkToFork (FSSpec *sourceFile, FSSpec *destFile,
- Boolean sourceRsrc, Boolean destRsrc);
- /* This routine copies a fork from the sourceFile to the destFile.
- The fork chosen in each case is determined by the sourceRsrc and
- destRsrc switches. If true, the resource fork is used, if false,
- the data fork.
- */
-
- extern pascal OSStatus CopyFile (FSSpec *source, FSSpec *dest);
- /* Copies a file from source to dest. Any file already existing at dest is
- destroyed. Also set the catalogue info for the dest file from the source file.
- */
-
- extern pascal OSStatus GetFSSpecGivenFileRefNum(SInt16 fileRefNum, FSSpec *fss);
- /* Consults the FCB of the open file to find out its FSSpec. */
-
- extern pascal OSStatus FileRefNumIsWriteable(SInt16 fileRefNum, Boolean *writeable);
- /* Returns true if the FCB says that the file is writable. */
-
- extern pascal Boolean EqualFSSpec(const FSSpec *fss1, const FSSpec *fss2);
- /* Returns true if fss1 and fss2 denote the same file system object. */
-
- extern pascal OSErr ICUFSSpecToFullPath (const FSSpec fss, Str255 path);
- /* Returns a full path for the given FSSpec. Actually it's an approximation
- (it doesn't handle paths longer than 256 characters) but, seeing as
- IC only uses this path for display purposes, that's not a problem.
- */
-
- extern pascal ICError ICFileSpecToFSSpec (ICFileSpecHandle fileSpec, Boolean canInteract, FSSpec *fss);
- extern pascal OSErr FSSpecToICFileSpec (FSSpec *fss, ICFileSpecHandle fileSpec);
- /* These routines convert ICFileSpecHandles to FSSpecs and vice versa.
- An ICFileSpecHandle is basically an AliasHandle with some fields tacked
- on the front to make it usable by System 6 clients. Under System 7 these
- routines are basically wrappers for standard Alias Manager routines.
- Note that in poth of these routines, the caller is responsible for allocating
- and deallocating the ICFileSpecHandle, and we just resize it if necessary.
- */
-
- extern pascal Boolean IsApplicationType(OSType fdType);
- /* Returns true if fdType is common type for applications. */
-
- /* ***** IC API Stuff ***** */
-
- /* These are simple wrappers around the IC API for getting and setting PString preferences. */
-
- extern pascal ICError ICGetPrefStr (ICInstance inst, ConstStr255Param key, ICAttr *attr, Str255 str);
- extern pascal ICError ICSetPrefStr (ICInstance inst, ConstStr255Param key, ICAttr attr, ConstStr255Param str);
-
- /* ***** Text Utilities Stuff ***** */
-
- /* These are simple wrappers around the toolbox NumToString and StringToNum routines. */
-
- #if 0
- // No point having this is C because you can't return a Str255,
- // and the obvious conversion is no advantage over NumToString.
- extern pascal Str255 DecStr(SInt32 aNumber);
- #endif
-
- extern pascal SInt32 DecVal(ConstStr255Param aString);
-
-
- /* These are simple routines to convert between strings and OSTypes. */
-
- extern pascal OSType StringToOSType (ConstStr255Param aString);
-
- #if 0
- extern pascal Str15 OSTypeToString (OSType anOSType);
-
- extern pascal Str255 TPCopy (ConstStr255Param sourceString, SInt16 startIndex, SInt16 count);
- /* TPCopy provides a version of the Pascal built-in function Copy that
- implements the Think Pascal semantics. This is much more useful
- than routine built-in to Metrowerks Pascal, which implements the
- semantics of MPW Pascal.
- The routine extracts count characters from the source string
- starting at character position start. If there aren't enough characters
- in the string, it returns what there are.
- */
-
- extern pascal Str255 GetOwnerName(void);
- /* This function returns the Owner name for the Macintosh
- as defined in the Sharing Setup control panel.
- */
-
- extern pascal Str255 NewLookupError(SInt16 NersID, OSStatus errNum);
- /* Return the string associated with errNum. The 'Ners' resource
- has a ResEdit template of...
- *****
- LSTB
- errNum
- DLNG
- errstr
- PSTR
- *****
- LSTE
- There must be a terminating entry with error number of 0 that contains
- the default error message.
- */
-
- #endif
-
- extern pascal void NewLookupErrorC(SInt16 NersID, OSStatus errNum, Str255 result);
- /* A procedure version of the above, for access from lame C-like
- languages.
- */
-
- /* ***** Truly Misc Stuff ***** */
-
- extern pascal Boolean TrapAvailable (SInt16 theTrap);
- /* Returns true if theTrap is available on this machine.
- This routine is implemented by the book, the book being Inside Macintosh.
- */
-
- #if ! GENERATINGCFM
-
- extern pascal void MakeDataExecutableAs68KCode(void *base, SInt32 size);
- /* Makes some data executable as 68K code. This is distinct
- from the system call MakeDataExecutable, which makes data
- executable as PowerPC code.
- This call makes sense even on PPC machines, for example
- the old contents of the memory might be currently cached
- in the DR (Dynamic Recompiling) translation cache.
- */
-
- #endif
-
- extern pascal ICError ICUCanInteract(void);
- /* Returns noErr if user interaction is possible. Basically a wrapper
- around AEInteractWithUser that makes it System 6 safe.
- */
-
- extern pascal void SafeAppendMenu (MenuHandle menuH, ConstStr255Param itemText);
- /* The system AppendMenu interprets the new menu item in strange
- ways, attempting to glean command key and other information from
- the text. This is obviously bad for things like the items on the
- Archie menu. This 'safe' version of the AppendMenu routine
- sets the text window interpreting it.
- */
-